package com.ezandroid.alphago;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

public class ManualPagerAdapter extends PagerAdapter {

    private ArrayList<View> mChildren = new ArrayList<View>();

    @Override
    public int getCount() {
        return mChildren.size();
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View v = mChildren.get(position);
        container.addView(v);
        return v;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(mChildren.get(position));
    }

    public void addChild(View v) {
        mChildren.add(v);
    }

    public void addChild(View v, int index) {
        mChildren.add(index, v);
    }

    public void removeChild(View v) {
        mChildren.remove(v);
    }

    public void removeChild(int index) {
        mChildren.remove(index);
    }
}
